package com.hiltony.web.controller;

import com.hiltony.web.mapper.LocationMapper;
import com.hiltony.web.model.Location;
import com.hiltony.web.model.LocationWarning;
import com.hiltony.web.model.Member;
import com.hiltony.web.service.MemberService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yx on 2017/4/15.
 */

@Controller
@RequestMapping("/action")
public class ActionController {

    @Resource
    private MemberService memberService;

    @Resource
    private LocationMapper locationMapper;



    @RequestMapping("/listActionRecord")
    public String getActionRecord(Member member, HttpServletRequest request, Model model) {
        List<Member> members = memberService.getMemberList(new Member());
        Location memberLocation = new Location();
        if(member==null || member.getMemberId()==null){
            memberLocation.setMemberId(members.get(0).getMemberId());
        }
        else {
            memberLocation.setMemberId(member.getMemberId());
        }
        if(member.getTrackDayStr()!=null && !member.getTrackDayStr().equals("")) {
            memberLocation.setStartTimeStr(member.getTrackDayStr());
        }
        List<Location> records = locationMapper.getLocationList(memberLocation);
        model.addAttribute("records",records);
        members.addAll(members);
        model.addAttribute("memberList", members);
        return "action_record_index";

    }

    @RequestMapping("/listWarning")
    public String getActionWarningList(Member member, HttpServletRequest request, Model model) {
        List<Member> members = memberService.getMemberList(new Member());
        LocationWarning locationWarning = new LocationWarning();
        if(member==null||member.getMemberId()==null){
            locationWarning.setMemberId(members.get(0).getMemberId());
        }
        else {
            locationWarning.setMemberId(member.getMemberId());
        }
        if(member.getTrackDayStr()!=null && !member.getTrackDayStr().equals("")) {
            locationWarning.setWarningStr(member.getTrackDayStr());
        }
        members.addAll(members);
        model.addAttribute("memberList", members);
        model.addAttribute("warnings",locationMapper.getLocationWarningList(locationWarning));
        return "action_warning_index";

    }
}
